import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { StaticResUrl } from "../../../resource/StaticResUrl";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { CopyConfig } from "../../../resource/CopyConfig";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GuildDefenseBuildInfoPanel } from "./build/GuildDefenseBuildInfoPanel";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { CopyUtil } from "../CopyUtil";
import { Language } from "../../../../../extend/language/Language";
import { Global } from "../../../../../com/gengine/global/Global";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class GuildDefenseInfoPanel
    
    export  class GuildDefenseInfoPanel extends View
    {
        constructor()
        {
            super();
            this.mouseEnabled = false;
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveMouseDown);
            return;
        }

        protected createChildren(): void
        {
            this._containBig = new Object /* flash.display.Sprite */();
            this._containSmall = new Object /* flash.display.Sprite */();
            this.addChild(this._containBig);
            this._materialLabel = ObjCreate.createGTextField("", 124, 12, 45, 25, this, new GTextFormat(FontUtil.xingkaiName, 20, 16777215, true, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._materialLabel.filters = [new Object /* flash.filters.GlowFilter */(544396, 1, 2, 2, 4)];
            this._downBtn = ObjCreate.createGButton("", 265, 17, 21, 20, this, "DownButton");
            this._downBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onDownBtnClick);
            this._bgBig = ObjCreate.createLoadedBitmap(StaticResUrl.GuildDefenseBg_big, 0, 0, this._containBig);
            this._ringLabel = ObjCreate.createGTextField("", 10, 50, 270, 20, this._containBig, new GTextFormat(null, 12, GlobalStyle.color5Uint));
            this.updateBossRing(0);
            this._difLabel = ObjCreate.createGTextField("", 120, 50, 270, 20, this._containBig, new GTextFormat(null, 12, GlobalStyle.color1Uint));
            this._expLabel = ObjCreate.createGTextField("", 10, 70, 270, 20, this._containBig, new GTextFormat(null, 12, 16776960));
            this.updateExp(0);
            this._conLabel = ObjCreate.createGTextField("", 10, 90, 270, 20, this._containBig, new GTextFormat(null, 12, 16776960));
            this.updateCon(0);
            this._tipLabel = ObjCreate.createGTextField("", 10, 110, 270, 60, this._containBig, new GTextFormat("", 12, GlobalStyle.color1Uint, null, null, null, null, null, null, 55, null, -55, 3));
            this._tipLabel.wordWrap = true;
            this._tipLabel.htmlText = CopyConfig.instance.getGuildCopyDesc(7);
            ObjCreate.createBg(10, 175, 270, 2, this._containBig, ImagesConst.Line);
            this._matLabel = ObjCreate.createGTextField("", 10, 180, 270, 20, this._containBig, new GTextFormat(null, 12, 16776960));
            this._buildInfoPanel = new GuildDefenseBuildInfoPanel();
            this._buildInfoPanel.x = 10;
            this._buildInfoPanel.y = 200;
            this._containBig.addChild(this._buildInfoPanel);
            this._bgSmall = ObjCreate.createLoadedBitmap(StaticResUrl.GuildDefenseBg_small, 0, 0, this._containSmall);
            return;
        }

        /* internal  */onDownBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._containBig.parent) 
            {
                this._containBig.parent.removeChild(this._containBig);
                this.addChildAt(this._containSmall, 0);
            }
            else 
            {
                this.addChildAt(this._containBig, 0);
                if (this._containSmall.parent) 
                {
                    this._containSmall.parent.removeChild(this._containSmall);
                }
            }
            return;
        }

        public updateInfos(): void
        {
            var loc1=Cache.instance.copy.guildDefenseCopyInfo;
            if (!loc1) 
            {
                return;
            }
            this._maxRing = CopyConfig.instance.getGuildDefenseDiffRing(loc1.difficulty);
            this._materialLabel.htmlText = HTMLUtil.addColor("" + loc1.score, "0xFFFFFF");
            this._difLabel.htmlText = HTMLUtil.addColor("（" + CopyUtil.getDifficultyDef(loc1.difficulty) + "）", GlobalStyle.color1);
            this._matLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(60441, loc1.matertial), "0xFFFF00");
            this._buildInfoPanel.updateLevelupBtnTooltip();
            return;
        }

        public updateBossRing(arg1: int): void
        {
            var loc1=Math.floor(arg1 / 5);
            if (loc1 >= this._maxRing) 
            {
                this._ringLabel.htmlText = HTMLUtil.addColor(Language.getString(60452), GlobalStyle.color5);
            }
            else 
            {
                this._ringLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(60440, loc1), GlobalStyle.color5);
            }
            if (this._difLabel) 
            {
                this._difLabel.x = this._ringLabel.x + this._ringLabel.textWidth + 5;
            }
            return;
        }

        public updateExp(arg1: int): void
        {
            this._expLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(60427, arg1), "0xFFFF00");
            return;
        }

        public updateCon(arg1: int): void
        {
            this._conLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(60428, arg1), "0xFFFF00");
            return;
        }

        public updateBuildInfos(): void
        {
            this._buildInfoPanel.updateBuildInfo();
            return;
        }

        public unableLevelButtons(): void
        {
            this._buildInfoPanel.unableLevelButtons();
            return;
        }

        public enableLevelButtons(): void
        {
            this._buildInfoPanel.enableLevelButtons();
            return;
        }

        /* internal  */onMoveMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target is flash.display.Sprite) 
            {
                startDrag();
                Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            }
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        /* internal */ /* var */_containBig: Object /* flash.display.Sprite */;

        /* internal */ /* var */_containSmall: Object /* flash.display.Sprite */;

        /* internal */ /* var */_materialLabel: GTextFiled;

        /* internal */ /* var */_downBtn: GButton;

        /* internal */ /* var */_bgBig: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_ringLabel: GTextFiled;

        /* internal */ /* var */_difLabel: GTextFiled;

        /* internal */ /* var */_expLabel: GTextFiled;

        /* internal */ /* var */_conLabel: GTextFiled;

        /* internal */ /* var */_tipLabel: GTextFiled;

        /* internal */ /* var */_matLabel: GTextFiled;

        /* internal */ /* var */_buildInfoPanel: GuildDefenseBuildInfoPanel;

        /* internal */ /* var */_bgSmall: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_maxRing: int=60;
    }
